package net.risesoft.risebi.collection.web.admin;

import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import net.risesoft.risebi.collection.commons.constants.SystemConstants;
import net.risesoft.risebi.collection.commons.hibernate.HibernateLoader;
import net.risesoft.risebi.collection.event.eventobj.EventObject;
import net.risesoft.risebi.collection.event.eventobj.SystemLogEventObj;
import net.risesoft.risebi.collection.model.Application;
import net.risesoft.risebi.collection.model.Catalog;
import net.risesoft.risebi.collection.model.DbColumn;
import net.risesoft.risebi.collection.model.Service;
import net.risesoft.risebi.collection.model.SoType;
import net.risesoft.risebi.collection.model.StatisticalObjectTreeNode;
import net.risesoft.risebi.collection.model.SystemLog;
import net.risesoft.risebi.collection.model.Template;
import net.risesoft.risebi.collection.model.User;
import net.risesoft.risebi.collection.service.ApplicationManager;
import net.risesoft.risebi.collection.service.CatalogManager;
import net.risesoft.risebi.collection.service.DbMetaDataManager;
import net.risesoft.risebi.collection.service.DynaBeanManager;
import net.risesoft.risebi.collection.service.SoTypeManager;
import net.risesoft.risebi.collection.service.StatisticalObjectTreeNodeManager;
import net.risesoft.risebi.collection.service.TemplateManager;
import net.risesoft.risebi.collection.web.BaseAction;
import net.risesoft.risebi.commons.hibernateextension.HibernateUtil;
import net.risesoft.risebi.commons.util.ContextUtil;
import net.risesoft.risebi.commons.util.GUID;
import net.risesoft.risebi.commons.util.JSONUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.LazyDynaBean;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
*
* @author <a href="mailto: dingzhaojun2046@hotmail.com">丁兆俊</a>
* @version $Revision$
* 
*/
@Namespace("/admin/CatalogAction")
public class CatalogAction extends BaseAction {
	private static final Logger logger = Logger.getLogger(CatalogAction.class);
	private static final long serialVersionUID = -2234876809053016176L;	
	
	private Catalog catalog;	
	private HashMap<String,Object> dynaBean;
	private HibernateLoader hibernateLoader;	
	
	private StatisticalObjectTreeNodeManager statisticalObjectTreeNodeManager;
	private ApplicationManager applicationManager;
	private CatalogManager catalogManager;
	private SoTypeManager soTypeManager;
	private DbMetaDataManager dbMetaDataManager;
	private DynaBeanManager dynaBeanManager;
	private TemplateManager templateManager;
	
	private String field; //Ext.ux.plugins.RemoteValidator
	private String value; //Ext.ux.plugins.RemoteValidator
	private String crud;
	private String jsonList;
	private String jsonAdd;
	private String jsonEdit;
	private String dirtyFile;
	
	private String serviceGuid;
	private String applicationGuid;
	private String applicationName;
	
	@Action(value="prepareAddDict",
			results={@Result(name="success", location="/admin/catalog/dictAdd.jsp")}
	)
	public String prepareAddDict() throws Exception {
		if(this.catalog==null) this.catalog = new Catalog();
		this.catalog.setService(this.getDefaultService());
		
		return SUCCESS;
	}

	@Action(value="prepareAddSo",
			results={@Result(name="success", location="/admin/catalog/soAdd.jsp")}
	)
	public String prepareAddSo() throws Exception {
		if(this.catalog==null) this.catalog = new Catalog();
		this.catalog.setService(this.getDefaultService());
		
		List<SoType> lst = soTypeManager.getByServiceGuid(this.getDefaultService().getGuid());
		this.json = JSONUtil.getJsonString("include","guid,name",lst);
		
		return SUCCESS;
	}

	@Action(value="prepareAddCatalog",
			results={@Result(name="success", location="/admin/catalog/catalogAdd.jsp")}
	)
	public String prepareAddCatalog() throws Exception {
		if(this.catalog==null) this.catalog = new Catalog();
		this.catalog.setService(this.getDefaultService());
		
		return SUCCESS;
	}
	
	@Action(value="add")
	public String add() throws Exception {
		User user = this.getSessionUser();
		
		LazyDynaBean ldb = new  LazyDynaBean();
		String err = "";
		try{
			String guid = new GUID().toString();
			catalog.setGuid(guid);
			catalog.setTabIndex(1d);
			
			catalogManager.saveObject(catalog);		
			
			ldb.set("guid", catalog.getGuid());
			ldb.set("code", catalog.getCode());
			ldb.set("name", catalog.getName());
			ldb.set("type", catalog.getType());
			ldb.set("soTypeGuid", catalog.getSoTypeGuid());
			ldb.set("appGuid", catalog.getAppGuid());
			ldb.set("enabled", catalog.getEnabled());
			ldb.set("tableName", catalog.getTableName());
			ldb.set("templateGuid", catalog.getTemplateGuid());
			ldb.set("tabIndex", catalog.getTabIndex());
			ldb.set("virtual", catalog.getVirtual());
			ldb.set("hierarchicalType", catalog.getHierarchicalType());	
			ldb.set("hierarchical_field_name", catalog.getHierarchical_field_name());
			ldb.set("segmentslength", catalog.getSegmentslength());
			
			String tableName = catalog.getTableName().trim();
			try{
				if(!dbMetaDataManager.checkTableExist(tableName)){
					DDL_CreateTable(tableName);
					
//		    		记录日志
		    		SystemLog systemLog = new SystemLog();
		    		systemLog.setOpterateType(SystemLog.OPTERATETYPE_ADD);
		    		systemLog.setUser(user);
		    		
		    		Service service = this.getDefaultService();
		    		systemLog.setServiceGuid(service.getGuid());
		    		
		    		EventObject systemLogEventObject = new SystemLogEventObj(this);
		    		Map systemLogMap = new HashMap();
		    		systemLogMap.put("systemLog", systemLog);
		    		systemLogMap.put("keyName", "catalogadd");
		    		systemLogMap.put("catalog", catalog);
		    		
		    		systemLogEventObject.setDataMap(systemLogMap);
		    		ContextUtil.getAc().publishEvent(systemLogEventObject);
				}
			}catch(Exception e){
				err = e.getMessage();
			}
	
			ldb.set("success", true);
			ldb.set("reason", "增加catalog成功!");
			
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", err + e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
		}

		return AJAX;
	}

	@Action(value="prepareEditDict",
			results={@Result(name="success", location="/admin/catalog/dictEdit.jsp")}
	)
	public String prepareEditDict() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		if(catalog.getEnabled() == null){
			catalog.setEnabled(false);
		}
		
		return SUCCESS;
	}

	@Action(value="prepareEditSo",
			results={@Result(name="success", location="/admin/catalog/soEdit.jsp")}
	)
	public String prepareEditSo() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		if(catalog.getEnabled() == null){
			catalog.setEnabled(false);
		}
		if(catalog.getVirtual() == null){
			catalog.setVirtual(false);
		}
		
		List<SoType> lst1 = soTypeManager.getByServiceGuid(this.getDefaultService().getGuid());
		this.json = JSONUtil.getJsonString("include","guid,name",lst1);
		
		List<Template> lst2 = templateManager.getAllBaseInfoTemplatesByApplication(catalog.getAppGuid());
		this.jsonList = JSONUtil.getJsonString("include","guid,name",lst2);
		
		List<DbColumn> lst3 = dbMetaDataManager.listAllColumns(catalog.getTableName());
		for(DbColumn f : lst3){
			f.setColumn_name(f.getColumn_name().toLowerCase());
			f.setComment(f.getComment().trim() + "--" + f.getColumn_name());
		}
		this.jsonEdit = JSONUtil.getJsonString("include", "column_name,comment", lst3);
		
		return SUCCESS;
	}

	@Action(value="prepareEditCatalog",
			results={@Result(name="success", location="/admin/catalog/catalogEdit.jsp")}
	)
	public String prepareEditCatalog() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		if(catalog.getEnabled() == null){
			catalog.setEnabled(false);
		}
		
		List<DbColumn> lst3 = dbMetaDataManager.listAllColumns(catalog.getTableName());
		for(DbColumn f : lst3){
			f.setColumn_name(f.getColumn_name().toLowerCase());
			f.setComment(f.getComment().trim() + "--" + f.getColumn_name());
		}
		this.jsonEdit = JSONUtil.getJsonString("include", "column_name,comment", lst3);
		
		return SUCCESS;
	}
	
	@Action(value="edit")
	public String edit() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("edit() - start"); //$NON-NLS-1$
		}

		LazyDynaBean ldb = new  LazyDynaBean();
		String err = "";
		try{
			Catalog catalogOld = (Catalog)catalogManager.getObject(Catalog.class, catalog.getGuid());
			String tableNameOld = catalogOld.getTableName().trim();
			String tableName = catalog.getTableName().trim();
			
			catalogOld.setGuid(catalog.getGuid());
			catalogOld.setCode(catalog.getCode());
			catalogOld.setName(catalog.getName());
			catalogOld.setTableName(catalog.getTableName());
			catalogOld.setEnabled(catalog.getEnabled());
			catalogOld.setVirtual(catalog.getVirtual());
			catalogOld.setHierarchicalType(catalog.getHierarchicalType());
			catalogOld.setHierarchical_field_name(catalog.getHierarchical_field_name());
			catalogOld.setSegmentslength(catalog.getSegmentslength());
			catalogOld.setTabIndex(catalog.getTabIndex());
			catalogOld.setType(catalog.getType());				
			catalogOld.setAppGuid(catalog.getAppGuid());
			catalogOld.setTemplateGuid(catalog.getTemplateGuid());
			if(catalog.getType()!=1){
				catalogOld.setSoTypeGuid(null);	
			}else{
				catalogOld.setSoTypeGuid(catalog.getSoTypeGuid());
			}
			
			catalogManager.saveObject(catalogOld);	
			
			ldb.set("guid", catalogOld.getGuid());
			ldb.set("code", catalogOld.getCode());
			ldb.set("name", catalogOld.getName());
			ldb.set("type", catalogOld.getType());
			ldb.set("soTypeGuid", catalogOld.getSoTypeGuid());
			ldb.set("appGuid", catalogOld.getAppGuid());
			ldb.set("enabled", catalogOld.getEnabled());
			ldb.set("tableName", catalogOld.getTableName());
			ldb.set("templateGuid", catalogOld.getTemplateGuid());
			ldb.set("tabIndex", catalogOld.getTabIndex());	
			ldb.set("virtual", catalogOld.getVirtual());
			ldb.set("hierarchicalType", catalogOld.getHierarchicalType());	
			ldb.set("hierarchical_field_name", catalogOld.getHierarchical_field_name());	
			ldb.set("segmentslength", catalogOld.getSegmentslength());
			
			if( !tableName.equalsIgnoreCase(tableNameOld) ){
				String dbName = dbMetaDataManager.getDatabaseProductName();
				if(dbMetaDataManager.checkTableExist(tableName)){
					err = "表：[" + tableName + "]已经存在！\r\n";
				}else{
					try{
						if(dbMetaDataManager.checkTableExist(tableNameOld)){
							if(dbName.indexOf("MySQL") > -1){
								dbMetaDataManager.executeDDL("ALTER TABLE " + tableNameOld + " RENAME " + tableName);
								
								hibernateLoader.loadNewDbDefinition(tableName);
							}else if("Oracle".equalsIgnoreCase(dbName)){
								dbMetaDataManager.executeDDL("RENAME " + tableNameOld + " TO " + tableName);
								
								hibernateLoader.loadNewDbDefinition(tableName);
							}else{
								dbMetaDataManager.executeDDL("ALTER TABLE " + tableNameOld + " RENAME " + tableName);
								
								hibernateLoader.loadNewDbDefinition(tableName);
							}	
						}else{
							DDL_CreateTable(tableName);
						}
					}catch(Exception e){
						logger.error("edit()", e); //$NON-NLS-1$

						err = e.getMessage();
					}	
				}					
			}
			
			User user = this.getSessionUser();
			
//    		记录日志
    		SystemLog systemLog = new SystemLog();
    		systemLog.setOpterateType(SystemLog.OPTERATETYPE_EDIT);
    		systemLog.setUser(user);
    		
    		Service service = this.getDefaultService();
    		systemLog.setServiceGuid(service.getGuid());
    		
    		EventObject systemLogEventObject = new SystemLogEventObj(this);
    		Map systemLogMap = new HashMap();
    		systemLogMap.put("systemLog", systemLog);
    		systemLogMap.put("keyName", "catalogedit");
    		systemLogMap.put("catalog", catalogOld);
    		
    		if( !tableName.equalsIgnoreCase(tableNameOld) ){
    			systemLogMap.put("renametable", "true");
    		}else{
    			systemLogMap.put("renametable", "false");
    		}
    		
    		systemLogEventObject.setDataMap(systemLogMap);
    		ContextUtil.getAc().publishEvent(systemLogEventObject);
			
			ldb.set("success", true);
			ldb.set("reason", "修改catalog成功!");
			
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			logger.error("edit()", e); //$NON-NLS-1$

			ldb.set("success", false);
			ldb.set("reason", err + e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
		}

		if (logger.isDebugEnabled()) {
			logger.debug("edit() - end"); //$NON-NLS-1$
		}
		return AJAX;
	}
	
	@Action(value="remove")
	public String remove() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("remove() - start"); //$NON-NLS-1$
		}

		LazyDynaBean ldb = new  LazyDynaBean();
		String err = "";
		try{
			catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
			String s = "";
			int count1 = catalogManager.getCount("select count(*) from SoCollectionMember c where c.so_guid='"+node+"'");
			int count2 = catalogManager.getCount("select count(*) from StatisticalObjectTreeNode c where c.catalog.guid='"+node+"'");
			int count3 = catalogManager.getCount("select count(*) from TemplateIndication c where c.related_Catalog_GUID like '%"+node+"%'");
			
			if(count1>0) s += "SoCollectionMember\r\n";			
			if(count2>0) s += "StatisticalObjectTreeNode\r\n";			
			if(count3>0) s += "TemplateIndication\r\n";			
			
			if(s.length()>0){				
				ldb.set("success", false);
				ldb.set("reason", "本catalog在以下表中使用：\r\n\r\n" + s + "\r\n  不能删除！！！");
				this.json = JSONObject.fromObject(ldb).toString();				
			}else{
				catalogManager.removeObject(Catalog.class, node); 
				
				String tableName = catalog.getTableName().trim();
				if(dbMetaDataManager.checkTableExist(tableName)){
					String dbName = dbMetaDataManager.getDatabaseProductName();
					try{
						SimpleDateFormat sdf = new SimpleDateFormat("'bak_'yyyy'_'MM'_'dd'_'HH'_'mm'_'ss'_'SS");
						String tableName2 = sdf.format(new Date());
		
						if(dbName.indexOf("MySQL") > -1){
							dbMetaDataManager.executeDDL("ALTER TABLE " + tableName + " RENAME " + tableName2);
						}else if("Oracle".equalsIgnoreCase(dbName)){
							dbMetaDataManager.executeDDL("RENAME " + tableName + " TO " + tableName2);
						}else{
							dbMetaDataManager.executeDDL("ALTER TABLE " + tableName + " RENAME " + tableName2);
						}
					}catch(Exception e){
						logger.error("remove()", e); //$NON-NLS-1$	
						err = e.getMessage();
					}
				}
				
				User user = this.getSessionUser();
				
//	    		记录日志
	    		SystemLog systemLog = new SystemLog();
	    		systemLog.setOpterateType(SystemLog.OPTERATETYPE_REMOVE);
	    		systemLog.setUser(user);
	    		
	    		Service service = this.getDefaultService();
	    		systemLog.setServiceGuid(service.getGuid());
	    		
	    		EventObject systemLogEventObject = new SystemLogEventObj(this);
	    		Map systemLogMap = new HashMap();
	    		systemLogMap.put("systemLog", systemLog);
	    		systemLogMap.put("keyName", "catalogremove");
	    		systemLogMap.put("catalog", catalog);
	    		
	    		systemLogEventObject.setDataMap(systemLogMap);
	    		ContextUtil.getAc().publishEvent(systemLogEventObject);
				
				ldb.set("success", true);
				ldb.set("reason", "删除catalog成功!");
				this.json = JSONObject.fromObject(ldb).toString();
			}
		}catch(Exception e){
			logger.error("remove()", e); //$NON-NLS-1$

			ldb.set("success", false);
			ldb.set("reason", err + e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
		}		
		
		if (logger.isDebugEnabled()) {
			logger.debug("remove() - end"); //$NON-NLS-1$
		}
		return AJAX;
	}
	
	@Action(value="initialSoType")
	public String initialSoType() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			Service service = this.getDefaultService();
			
			String[][] strList = {
					{"AAAAAAAAAAAAAAAAAAAAAAAAAAAA0001","d","地区","1"},
					{"AAAAAAAAAAAAAAAAAAAAAAAAAAAA0002","a","法人","2"},
					{"AAAAAAAAAAAAAAAAAAAAAAAAAAAA0003","b","产业活动单位","3"},
					{"AAAAAAAAAAAAAAAAAAAAAAAAAAAA0004","p","项目","4"}
			};
			
			SoType parentRpt = null;
			for(String[] strArray : strList){
				SoType soType = new SoType();
				
				List list = soTypeManager.find("from SoType t where t.service.guid='" + service.getGuid() + "' and t.code='" + strArray[1] + "'");
				if(list.size()>0){
					soType = (SoType)list.get(0);
				}else{
					soType.setGuid(strArray[0]);
					soType.setCode(strArray[1]);
				}				
				
				soType.setName(strArray[2]);
				soType.setTabIndex(Double.valueOf(strArray[3]));
				soType.setService(service);
				soTypeManager.saveObject(soType);
			}
			
			User user = this.getSessionUser();
			
//    		记录日志
    		SystemLog systemLog = new SystemLog();
    		systemLog.setOpterateType(SystemLog.OPTERATETYPE_PROCESS);
    		systemLog.setUser(user);
    		systemLog.setServiceGuid(service.getGuid());
    		
    		EventObject systemLogEventObject = new SystemLogEventObj(this);
    		Map systemLogMap = new HashMap();
    		systemLogMap.put("systemLog", systemLog);
    		systemLogMap.put("keyName", "sotypeinitial");
    		
    		systemLogEventObject.setDataMap(systemLogMap);
    		ContextUtil.getAc().publishEvent(systemLogEventObject);
			
			ldb.set("success", true);
			ldb.set("reason", "初始化成功!");
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
		}

		return AJAX;
	}
	
	@Action(value="updateSoTypes")
	public String updateSoTypes() throws Exception {
		User user = this.getSessionUser();
		
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			SoType[] ts = (SoType[])JSONUtil.stringToArray(this.json, SoType.class);
			for (SoType t : ts){
				boolean newed = false;
				
				if(t.getGuid()==null || t.getGuid().trim().length()==0 || t.getGuid().trim().startsWith("NEW")){
					t.setGuid(new GUID().toString());
					newed = true;
				}
				t.setService(this.getDefaultService());
				soTypeManager.saveObject(t);
				
//        		记录日志
        		SystemLog systemLog = new SystemLog();
        		if(newed)
        			systemLog.setOpterateType(SystemLog.OPTERATETYPE_ADD);
        		else
        			systemLog.setOpterateType(SystemLog.OPTERATETYPE_EDIT);
        		systemLog.setUser(user);
        		
        		Service service = this.getDefaultService();
        		systemLog.setServiceGuid(service.getGuid());
        		
        		EventObject systemLogEventObject = new SystemLogEventObj(this);
        		Map systemLogMap = new HashMap();
        		systemLogMap.put("systemLog", systemLog);
        		if(newed)
        			systemLogMap.put("keyName", "sotypeadd");
        		else
        			systemLogMap.put("keyName", "sotypeedit");
        		systemLogMap.put("sotype", t);
        		
        		systemLogEventObject.setDataMap(systemLogMap);
        		ContextUtil.getAc().publishEvent(systemLogEventObject);
			}
			
			ldb.set("success", true);
			ldb.set("reason", "保存成功!");
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}

	@Action(value="updateTableName")
	public String updateTableName() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		String err = "";
		try{
			List<Catalog> lst = catalogManager.getObjects(Catalog.class);
			for(Catalog c : lst){
				String code = c.getCode().trim();
				String tableName = "";
				switch(c.getType()){
				case 1://统计调查对象
					tableName = "dyna_so_" + code;
					break;
				case 2://指标自由项对应的主表
					tableName = "dyna_data_" + code;
					break;
				case 3://指标区域对应的细表
					tableName = "dyna_dataset_" + code;
					break;
				case 4://指标目录与分类
					tableName = "dyna_catalog_" + code;
					break;
				case 5://数据字典
					tableName = "dyna_dict_" + code;
					break;
				default:
					tableName = "dyna_other_" + code;
					break;
				}
				c.setTableName(tableName);
				try{
					catalogManager.saveObject(c);	
					String tableNameOld = "dyna_catalog_" + c.getCode().trim();
					if(dbMetaDataManager.checkTableExist(tableNameOld)){
						String dbName = dbMetaDataManager.getDatabaseProductName();
						try{
							if(dbName.indexOf("MySQL") > -1){
								dbMetaDataManager.executeDDL("ALTER TABLE " + tableNameOld + " RENAME " + tableName);
							}else if("Oracle".equalsIgnoreCase(dbName)){
								dbMetaDataManager.executeDDL("RENAME " + tableNameOld + " TO " + tableName);
							}else{
								dbMetaDataManager.executeDDL("ALTER TABLE " + tableNameOld + " RENAME " + tableName);
							}
						}catch(Exception e2){
							err += e2.getMessage();
						}
					}
				}catch(Exception e){
					err += e.getMessage();
				}					
			}
	
			if(err.length()>0){
				ldb.set("success", false);
				ldb.set("reason", err);
			}else{
				ldb.set("success", true);
				ldb.set("reason", "更改catalog对应的数据库表名称成功!");
			}
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", err + e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
		}
		return AJAX;
	}

	@Action(value="removeCatalogItem")
	public String removeCatalogItem() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim().toLowerCase();
		LazyDynaBean ldb = new  LazyDynaBean();		
		try{
			dynaBeanManager.removeObject(tableName, this.value);
			
			ldb.set("success", true);
			ldb.set("reason", "removeCatalogItem success!");
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}
		return AJAX;
	}

	@Action(value="removeSoType")
	public String removeSoType() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();		
		try{
			//catalogManager.execute("delete from SoType t where t.guid='" + this.node + "'");
			SoType soType = (SoType) soTypeManager.getObject(SoType.class, node);
			
			soTypeManager.removeObject(SoType.class, this.node);
			
			User user = this.getSessionUser();
			
//    		记录日志
    		SystemLog systemLog = new SystemLog();
    		systemLog.setOpterateType(SystemLog.OPTERATETYPE_REMOVE);
    		systemLog.setUser(user);
    		
    		Service service = this.getDefaultService();
    		systemLog.setServiceGuid(service.getGuid());
    		
    		EventObject systemLogEventObject = new SystemLogEventObj(this);
    		Map systemLogMap = new HashMap();
    		systemLogMap.put("systemLog", systemLog);
    		systemLogMap.put("keyName", "sotyperemove");
    		systemLogMap.put("sotype", soType);
    		
    		systemLogEventObject.setDataMap(systemLogMap);
    		ContextUtil.getAc().publishEvent(systemLogEventObject);
			
			ldb.set("success", true);
			ldb.set("reason", "删除统计对象类别成功！");
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
		}		

		return AJAX;
	}

	@Action(value="prepareAddCatalogItem",
			results={@Result(name="success", location="/admin/catalog/addCatalogItem.jsp")}
	)
	public String prepareAddCatalogItem() throws Exception {
		try{
			dynaBean = new HashMap<String,Object>();
			dynaBean.put("parentitem_guid", this.value);
		}catch(Exception e){
			e.printStackTrace();
		}

		return SUCCESS;
	}
	
	@Action(value="prepareEditCatalogItem",
			results={@Result(name="success", location="/admin/catalog/editCatalogItem.jsp")}
	)
	public String prepareEditCatalogItem() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim().toLowerCase();

		try{
			dynaBean = (HashMap<String, Object>)dynaBeanManager.getObject(tableName, this.value);
		}catch(Exception e){
			e.printStackTrace();
		}

		return SUCCESS;
	}

	@Action(value="addCatalogItem")
	public String addCatalogItem() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim().toLowerCase();
		LazyDynaBean ldb = new  LazyDynaBean();
		
		try{
			String guid = new GUID().toString();
			dynaBean.put("item_guid",guid);
			dynaBean.put("tabindex","2000");
			
			dynaBeanManager.saveObject(tableName, HibernateUtil.convertType(tableName, dynaBean,SystemConstants.REPORT_DYNAMODEL));		
			
			ldb.set("success", true);
			ldb.set("item_guid", guid);
			ldb.set("reason", "addCatalogItem success!");
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}		
		return AJAX;
	}

	@Action(value="editCatalogItem")
	public String editCatalogItem() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim().toLowerCase();
		LazyDynaBean ldb = new  LazyDynaBean();
		
		try{
			dynaBeanManager.saveObject(tableName, HibernateUtil.convertType(tableName, dynaBean,SystemConstants.REPORT_DYNAMODEL));		
			
			ldb.set("success", true);
			ldb.set("reason", "editCatalogItem success!");
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}
		return AJAX;
	}

	@Action(value="validateTableName")
	public String validateTableName() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();		
		String tableName = this.value.trim();
		
		if("c".equalsIgnoreCase(this.crud)){
			if(dbMetaDataManager.checkTableExist(tableName)){
				ldb.set("success", true);
				ldb.set("valid", false);
				ldb.set("reason", "数据库中存在表：" + tableName + "，请选择其他的表名称！");			
			}else{		
				ldb.set("success", true);
				ldb.set("valid", true);
				ldb.set("reason", "数据库中不存在这个表，可以使用这个名称！");			
			}			
		}else{
			String tableName_Old = this.node.trim();
			if(tableName.equalsIgnoreCase(tableName_Old)){
				ldb.set("success", true);
				ldb.set("valid", true);
				ldb.set("reason", "表名称没有改变！");	
			}else{
				if(dbMetaDataManager.checkTableExist(tableName)){
					ldb.set("success", true);
					ldb.set("valid", false);
					ldb.set("reason", "数据库中存在表：" + tableName + "，请选择其他的表名称！");			
				}else{		
					ldb.set("success", true);
					ldb.set("valid", true);
					ldb.set("reason", "数据库中不存在这个表，可以使用这个名称！");			
				}
			}
		}		
		
		this.json = JSONObject.fromObject(ldb).toString();
		return AJAX;
	}
	
	@Action(value="validateField")
	public String validateField() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();		
		if("catalog.tableName".equals(this.field)){
			if(dbMetaDataManager.checkTableExist(this.value.trim())){
				ldb.set("success", true);
				ldb.set("valid", false);
				ldb.set("reason", "该表在数据库中已经存在，请检查数据库！");
			}else{
				ldb.set("success", true);
				ldb.set("valid", true);
				ldb.set("reason", "");
			}
		}
		
		this.json = JSONObject.fromObject(ldb).toString();	

		return AJAX;
	}
	
	@Action(value="validateFieldItem")
	public String validateFieldItem() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("validateFieldItem() - start"); //$NON-NLS-1$
		}

		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim().toLowerCase();
		LazyDynaBean ldb = new  LazyDynaBean();		
		try{
			if("dynaBean.item_code".equals(this.field)){
				List lst = dynaBeanManager.find("from " + tableName + " t where t.item_code = '" + this.value + "'");
				if("c".equals(this.crud)){
					if(lst.size()>0){
						ldb.set("success", true);
						ldb.set("valid", false);
						ldb.set("reason", "catalog的代码重复。");
						this.json = JSONObject.fromObject(ldb).toString();
						

						if (logger.isDebugEnabled()) {
							logger.debug("validateFieldItem() - end"); //$NON-NLS-1$
						}
						return AJAX;
					}
				}else{
					if(lst.size()>0){
						HashMap hm = (HashMap<String,Object>)lst.get(0);
						if(!((String)hm.get("item_guid")).equalsIgnoreCase(this.source)){
							ldb.set("success", true);
							ldb.set("valid", false);
							ldb.set("reason", "catalog的代码重复。");
							this.json = JSONObject.fromObject(ldb).toString();
							

							if (logger.isDebugEnabled()) {
								logger.debug("validateFieldItem() - end"); //$NON-NLS-1$
							}
							return AJAX;						
						}
					}
				}			
			}else if("dynaBean.item_name".equals(this.field)){
				List lst = dynaBeanManager.find("from " + tableName + " t where t.item_name = '" + this.value + "'");
				if("c".equals(this.crud)){
					if(lst.size()>0){
						ldb.set("success", true);
						ldb.set("valid", false);
						ldb.set("reason", "catalog的名称重复。");
						this.json = JSONObject.fromObject(ldb).toString();
						

						if (logger.isDebugEnabled()) {
							logger.debug("validateFieldItem() - end"); //$NON-NLS-1$
						}
						return AJAX;
					}
				}else{
					if(lst.size()>0){
						HashMap hm = (HashMap<String,Object>)lst.get(0);
						if(!((String)hm.get("item_guid")).equalsIgnoreCase(this.source)){
							ldb.set("success", true);
							ldb.set("valid", false);
							ldb.set("reason", "catalog的名称重复。");
							this.json = JSONObject.fromObject(ldb).toString();
							

							if (logger.isDebugEnabled()) {
								logger.debug("validateFieldItem() - end"); //$NON-NLS-1$
							}
							return AJAX;						
						}
					}
				}			
			}
			ldb.set("success", true);
			ldb.set("valid", true);
			ldb.set("reason", "validateFieldItem success");
			this.json = JSONObject.fromObject(ldb).toString();			
		}catch(Exception e){
			logger.error("validateFieldItem()", e); //$NON-NLS-1$

			ldb.set("success", true);
			ldb.set("valid", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();			
		}
		

		if (logger.isDebugEnabled()) {
			logger.debug("validateFieldItem() - end"); //$NON-NLS-1$
		}
		return AJAX;		
	}

	/**
     * A default implementation that validates nothing.
     * Subclasses should override this method to provide validations.
     */
    public void validate() {
    }

    @Action(value="prepareManageFields",
			results={@Result(name="success", location="/admin/catalog/manageFields.jsp")}
	)
	public String prepareManageFields() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		try{
			List lst = dbMetaDataManager.listAllTypes();
			HashSet hs = new HashSet();
			for(Object o : lst){
				DynaBean db = (DynaBean)o;
				hs.add((String)db.get("type_name"));
			}
			
			ArrayList al = new ArrayList();
			for(Object o : hs){
				LazyDynaBean ldb = new LazyDynaBean();
				ldb.set("data_type", (String)o);
				ldb.set("type_name", (String)o);
				al.add(ldb);
			}
			this.json = JSONUtil.getJsonString("include", "data_type,type_name", al);
		}catch(Exception e){
			e.printStackTrace();
		}
		return SUCCESS;
	}

    @Action(value="listCatalog",
			results={@Result(name="success", location="/admin/catalog/listCatalog.jsp")}
	)
	public String listCatalog() throws Exception {
    	this.serviceGuid = this.getDefaultService().getGuid();
		return SUCCESS;
	}
	
    @Action(value="listSo",
			results={@Result(name="success", location="/admin/catalog/listSo.jsp")}
	)
	public String listSo() throws Exception {
		Application app = (Application)applicationManager.getObject(Application.class, this.applicationGuid);
		this.applicationName = app.getChineseName();
		
		List<SoType> lst = soTypeManager.getObjects(SoType.class);
		this.json = JSONUtil.getJsonString("include","guid,name",lst);
		
		List<Template> lst2 = templateManager.getAllBaseInfoTemplatesByApplication(this.applicationGuid);
		this.jsonList = JSONUtil.getJsonString("include","guid,name",lst2);

		return SUCCESS;
	}
	
    @Action(value="listTable",
			results={@Result(name="success", location="/admin/catalog/listTable.jsp")}
	)
	public String listTable() throws Exception {		
		return SUCCESS;
	}
	
    @Action(value="listDict",
			results={@Result(name="success", location="/admin/catalog/listDict.jsp")}
	)
	public String listDict() throws Exception {
    	this.serviceGuid = this.getDefaultService().getGuid();
		return SUCCESS;
	}

    @Action(value="listSoItemTreeGrid",
			results={@Result(name="success", location="/admin/catalog/soItemList-treeGrid.jsp")}
	)
	public String listSoItemTreeGrid() throws Exception {
		return SUCCESS;
	}

    @Action(value="listSoItemFlatGrid",
			results={@Result(name="success", location="/admin/catalog/soItemList-flatGrid.jsp")}
	)
	public String listSoItemFlatGrid() throws Exception {
    	catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim().toLowerCase();
		this.json = catalogManager.buildStoreFieldsConfig(tableName);
		this.jsonList = catalogManager.buildStoreFieldsCreateConfig(tableName);
		this.jsonEdit = catalogManager.buildGridColumnsWithFilterConfig(tableName);
		
		return SUCCESS;
	}
    
    
    
    @Action(value="listItems",
			results={@Result(name="success", location="/admin/catalog/listItems.jsp")}
	)
	public String listItems() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim().toLowerCase();
		this.json = catalogManager.buildFilterConfig(tableName);
		
		return SUCCESS;
	}

    @Action(value="prepareSelectSoItem",
			results={@Result(name="success", location="/admin/catalog/selectSoItem.jsp")}
	)
	public String prepareSelectSoItem() throws Exception {
		StatisticalObjectTreeNode soTreeNode = (StatisticalObjectTreeNode)statisticalObjectTreeNodeManager.getObject(StatisticalObjectTreeNode.class, node);
		
		catalog = soTreeNode.getCatalog();
		String tableName = catalog.getTableName().trim().toLowerCase();
		this.json = catalogManager.buildFilterConfig(tableName); 

		return SUCCESS;
	}

    @Action(value="listSoType",
			results={@Result(name="success", location="/admin/catalog/soTypeList.jsp")}
	)
	public String listSoType() throws Exception {
		return SUCCESS;
	}

	@Action(value="listDictItem",
			results={@Result(name="success", location="/admin/catalog/listDictItem.jsp")}
	)
	public String listDictItem() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim().toLowerCase();
		
		List lst = dynaBeanManager.find("select distinct t.item_type from " + tableName + " t");
		ArrayList alist = new ArrayList();
		for(Object o : lst){
			Map map = new HashMap();
			map.put("guid", (String)o);
			map.put("item_type", (String)o);
			alist.add(map);
		}			
		
		this.json = JSONUtil.getJsonString(null, null, alist);
		
		return SUCCESS;
	}

	public String listCatalogItem() throws Exception {
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);

		return "listCatalogItem";
	}

	@Action(value="refreshJson")
	public String refreshJson() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("refreshJson() - start"); //$NON-NLS-1$
		}

		if("jsonAllCatalogs".equalsIgnoreCase(this.whichJson)){
			List allCatalogs = catalogManager.getObjects(Catalog.class);	
			this.json = JSONUtil.getJsonString("include","guid,code,name,type,enabled,tabIndex",allCatalogs);

			if (logger.isDebugEnabled()) {
				logger.debug("refreshJson() - end"); //$NON-NLS-1$
			}
			return AJAX;
		}else if("jsonPagedCatalogs".equalsIgnoreCase(this.whichJson)){
			if(catalog==null) catalog = new Catalog();
			
			Service service = this.getDefaultService();
			catalog.setService(service);
			
			Map map = (Map)catalogManager.getPagedCatalog(catalog, start, limit);
			this.json = JSONUtil.getJsonString("exclude","application,soType,service,template",map);
			
			return AJAX;
		}else if("jsonSoTypes".equalsIgnoreCase(this.whichJson)){
			List<SoType> lst = soTypeManager.getByServiceGuid(this.getDefaultService().getGuid());
			this.json = JSONUtil.getJsonString("exclude","service",lst);
			
			return AJAX;
		}else if("jsonSoByApp".equalsIgnoreCase(this.whichJson)){
			List<Catalog> lst = catalogManager.getCatalogWithSoByApp(this.applicationGuid,false);
			List newList = new ArrayList();
			for(Catalog t : lst){
				Map map = new HashMap();
				map.put("guid", t.getGuid());
				map.put("name", t.getName());
				newList.add(map);
			}
			this.json = JSONUtil.getJsonString(null,null,newList);

			return AJAX;
		}
		
		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim();   		
		if(dbMetaDataManager.checkTableExist(tableName)){
			try{
				if("jsonFields".equalsIgnoreCase(this.whichJson)){
					List lst = dbMetaDataManager.listAllColumns(tableName);
					this.json = JSONUtil.getJsonString(null, null, lst);					
				}else if("jsonRelations".equalsIgnoreCase(this.whichJson)){
					List lst = dbMetaDataManager.listAllRelations(tableName);
					//List lst = dbMetaDataManager.listAllExportedKeys("dyna_employee");
					this.json = JSONUtil.getJsonString(null, null, lst);
				}else if("jsonIndexs".equalsIgnoreCase(this.whichJson)){
					List lst = dbMetaDataManager.listAllIndexs(tableName);
					this.json = JSONUtil.getJsonString(null, null, lst);
				}else if("jsonTypes".equalsIgnoreCase(this.whichJson)){
					List lst = dbMetaDataManager.listAllTypes();
					this.json = JSONUtil.getJsonString("include", "data_type,type_name", lst);
				}else if("jsonAllCatalogItems".equalsIgnoreCase(this.whichJson)){
					catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
					List lst = dynaBeanManager.getObjects(catalog.getTableName().trim().toLowerCase());
					//this.json = JSONUtil.getJsonString("include", "item_guid,parentitem_guid,item_code,item_name,tabindex", lst);
					this.json = JSONUtil.getJsonString(null, null, lst);
				}
			}catch(Exception e){
				logger.error("refreshJson()", e); //$NON-NLS-1$

				e.printStackTrace();
			}
		}
		

		if (logger.isDebugEnabled()) {
			logger.debug("refreshJson() - end"); //$NON-NLS-1$
		}
		return AJAX;
	}

	@Action(value="dropTableColumn")
	public String dropTableColumn() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("dropTableColumn() - start"); //$NON-NLS-1$
		}

		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim();
		LazyDynaBean ldb = new  LazyDynaBean();
		
		if(dbMetaDataManager.checkTableExist(tableName)){
			try{
				dbMetaDataManager.executeDDL("ALTER TABLE " + tableName + " DROP COLUMN " + this.field);
				hibernateLoader.loadNewDbDefinition(tableName);
				
				User user = this.getSessionUser();
				
//	    		记录日志
	    		SystemLog systemLog = new SystemLog();
	    		systemLog.setOpterateType(SystemLog.OPTERATETYPE_REMOVE);
	    		systemLog.setUser(user);
	    		
	    		Service service = this.getDefaultService();
	    		systemLog.setServiceGuid(service.getGuid());
	    		
	    		EventObject systemLogEventObject = new SystemLogEventObj(this);
	    		Map systemLogMap = new HashMap();
	    		systemLogMap.put("systemLog", systemLog);
	    		systemLogMap.put("keyName", "tablefieldremove");
	    		systemLogMap.put("tableName", tableName);
	    		systemLogMap.put("field", field);
	    		
	    		systemLogEventObject.setDataMap(systemLogMap);
	    		ContextUtil.getAc().publishEvent(systemLogEventObject);
				
				ldb.set("success", true);
				ldb.set("reason", "删除字段成功");
				this.json = JSONObject.fromObject(ldb).toString();
			}catch(Exception e){
				logger.error("dropTableColumn()", e); //$NON-NLS-1$

				ldb.set("success", false);
				ldb.set("reason", e.getMessage());
				this.json = JSONObject.fromObject(ldb).toString();
			}
		}
		

		if (logger.isDebugEnabled()) {
			logger.debug("dropTableColumn() - end"); //$NON-NLS-1$
		}
		return AJAX;
	}

	@Action(value="refreshHbm")
	public String refreshHbm() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		ArrayList<String> tableList = new ArrayList<String>();
		
		try{
			if(node.equalsIgnoreCase("rebuildAllHbm")){
				List<Catalog> lst = catalogManager.getAllOrderByTabIndex();
				for(Catalog c : lst){
					tableList.add(c.getTableName().trim());
				}
			}else{
				catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
				tableList.add(catalog.getTableName().trim());
			}
			
			hibernateLoader.loadNewDbDefinition(tableList);
			
			ldb.set("success", true);
			ldb.set("reason", "重建hbm映射文件：【成功！】");	
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
		}
		
		this.json = JSONObject.fromObject(ldb).toString();		
		return AJAX;
	}
	
	@Action(value="createTable")
	public String createTable() throws Exception {
		String tableName = node;
		LazyDynaBean ldb = new  LazyDynaBean();
		String reason = "";
		
		if(!dbMetaDataManager.checkTableExist(tableName)){
			try{
				String catalogCode = "";
				int catalogType = 0; //指标自由项对应的主表
				if(tableName.trim().toLowerCase().startsWith("dyna_dataset_")){
					catalogType = 3; //指标区域对应的细表
					catalogCode = tableName.substring(12);
				}else{
					catalogType = 2; //指标自由项对应的主表
					catalogCode = tableName.substring(9);
				}
				String guid = new GUID().toString();
				Catalog catalog = new Catalog();
				catalog.setGuid(guid);
				catalog.setCode(catalogCode);
				catalog.setName(catalogCode);
				catalog.setTableName(tableName);
				catalog.setType(catalogType);
				catalog.setEnabled(true);
				catalog.setHierarchicalType(0);
				catalog.setTabIndex(100.00);				
				catalogManager.saveObject(catalog);				
				
				String dbName = dbMetaDataManager.getDatabaseProductName();				
				JSONArray jsonArray = JSONArray.fromObject(this.json);
				if(dbName.indexOf("MySQL") > -1){
					String DDL = "CREATE TABLE " + tableName + " (\r\n";
					for (int i=0;i<jsonArray.size();i++){
						String columnName = jsonArray.getJSONObject(i).getString("column_name");
						String columnType = "";
						switch(jsonArray.getJSONObject(i).getInt("data_type")){
						case 2:
							columnType = " bigint ";
							break;
						case 3:
							columnType = " double ";
							break;
						default:
							columnType = " varchar(50) ";						
						}
						DDL += columnName + columnType + "DEFAULT NULL, \r\n";
					}
					DDL += "reportinstance_guid varchar(38) NOT NULL, \r\n";
					DDL += "tabindex double DEFAULT NULL, \r\n";
					if(tableName.toLowerCase().startsWith("dyna_dataset_")){
						DDL += "item_guid varchar(38) NOT NULL, \r\n";
						DDL += "PRIMARY KEY (item_guid), \r\n";
						DDL += "KEY reportinstance_guid (reportinstance_guid) \r\n";
					}else{
						DDL += "PRIMARY KEY (reportinstance_guid) \r\n";
					}
					DDL += ")";
					
					try{						
						dbMetaDataManager.executeDDL(DDL);
						hibernateLoader.loadNewDbDefinition(tableName);
						reason = reason + "\r\n" + DDL + "\r\n  [成功创建数据库表！]";
					}catch(Exception e){
						reason = reason + "\r\n" + DDL + "\r\n  [错误！," + e.getMessage() + "]";
					}	
				}else if("Oracle".equalsIgnoreCase(dbName)){
					String DDL = "CREATE TABLE " + tableName + " (\r\n";
					for (int i=0;i<jsonArray.size();i++){
						String columnName = jsonArray.getJSONObject(i).getString("column_name");
						String columnType = "";
						switch(jsonArray.getJSONObject(i).getInt("data_type")){
						case 2:
							columnType = " NUMERIC(5,0) ";
							break;
						case 3:
							columnType = " NUMERIC(20,3) ";
							break;
						default:
							columnType = " VARCHAR(50) ";						
						}
						DDL += columnName + columnType + ", ";
					}					
					DDL += "reportinstance_guid varchar(38) NOT NULL, \r\n";
					DDL += "tabindex double, \r\n";
					if(tableName.toLowerCase().startsWith("dyna_dataset_")){
						DDL += "item_guid varchar(38) NOT NULL, \r\n";
						DDL += "PRIMARY KEY (item_guid) \r\n";							
					}else{
						DDL += "PRIMARY KEY (reportinstance_guid) \r\n";
					}
					DDL += ")";
					
					try{
						dbMetaDataManager.executeDDL(DDL);
						hibernateLoader.loadNewDbDefinition(tableName);
						reason = reason + "\r\n" + DDL + "\r\n  [成功创建数据库表！]";
					}catch(Exception e){
						reason = reason + "\r\n" + DDL + "\r\n  [错误！," + e.getMessage() + "]";
					}	
				}
				
				if(reason.indexOf("[成功创建数据库表！]")==-1){
					ldb.set("success", false);
				}else{
					ldb.set("success", true);
					
					User user = this.getSessionUser();
					
//		    		记录日志
		    		SystemLog systemLog = new SystemLog();
		    		systemLog.setOpterateType(SystemLog.OPTERATETYPE_ADD);
		    		systemLog.setUser(user);
		    		
		    		Service service = this.getDefaultService();
		    		systemLog.setServiceGuid(service.getGuid());
		    		
		    		EventObject systemLogEventObject = new SystemLogEventObj(this);
		    		Map systemLogMap = new HashMap();
		    		systemLogMap.put("systemLog", systemLog);
		    		systemLogMap.put("keyName", "catalogadd");
		    		systemLogMap.put("catalog", catalog);
		    		
		    		systemLogEventObject.setDataMap(systemLogMap);
		    		ContextUtil.getAc().publishEvent(systemLogEventObject);
				}
				ldb.set("reason", reason);
				this.json = JSONObject.fromObject(ldb).toString();
			}catch(Exception e){
				ldb.set("success", false);
				ldb.set("reason", reason + "\r\n" + e.getMessage());
				this.json = JSONObject.fromObject(ldb).toString();
			}			
		}else{
			ldb.set("success", false);
			ldb.set("reason", "数据库表已经存在！");
			this.json = JSONObject.fromObject(ldb).toString();
		}

		return AJAX;
	}

	@Action(value="addTableColumn")
	public String addTableColumn() throws Exception {
		String tableName = node;
		LazyDynaBean ldb = new  LazyDynaBean();
		String reason = "";
		
		if(dbMetaDataManager.checkTableExist(tableName)){
			try{
				String dbName = dbMetaDataManager.getDatabaseProductName();				
				JSONArray jsonArray = JSONArray.fromObject(this.json);
				if(dbName.indexOf("MySQL") > -1){
					for (int i=0;i<jsonArray.size();i++){
						String columnName = jsonArray.getJSONObject(i).getString("column_name");
						String columnType = "";
						switch(jsonArray.getJSONObject(i).getInt("data_type")){
						case 2:
							columnType = "bigint";
							break;
						case 3:
							columnType = "double";
							break;
						default:
							columnType = "varchar(50)";						
						}
						String DDL = "ALTER TABLE " + tableName + " ADD COLUMN " + columnName + " " + columnType + " DEFAULT NULL";
						try{
							dbMetaDataManager.executeDDL(DDL);
							hibernateLoader.loadNewDbDefinition(tableName);
							reason = reason + "\r\n" + DDL + "\r\n  [success!]";
						}catch(Exception e){
							reason = reason + "\r\n" + DDL + "\r\n  [" + e.getMessage() + "]";
						}	
					}
				}else if("Oracle".equalsIgnoreCase(dbName)){
					for (int i=0;i<jsonArray.size();i++){
						String columnName = jsonArray.getJSONObject(i).getString("column_name");
						String columnType = "";
						switch(jsonArray.getJSONObject(i).getInt("data_type")){
						case 2:
							columnType = "NUMERIC(5,0)";
							break;
						case 3:
							columnType = "NUMERIC(19,3)";
							break;
						default:
							columnType = "VARCHAR(50)";						
						}
						String DDL = "ALTER TABLE " + tableName + " ADD COLUMN " + columnName + " " + columnType + " NULL";
						try{
							dbMetaDataManager.executeDDL(DDL);
							hibernateLoader.loadNewDbDefinition(tableName);
							reason = reason + "\r\n" + DDL + "\r\n  [success!]";
						}catch(Exception e){
							reason = reason + "\r\n" + DDL + "\r\n  [" + e.getMessage() + "]";
						}	
					}					
				}
				
				User user = this.getSessionUser();
				
//	    		记录日志
	    		SystemLog systemLog = new SystemLog();
	    		systemLog.setOpterateType(SystemLog.OPTERATETYPE_ADD);
	    		systemLog.setUser(user);
	    		
	    		Service service = this.getDefaultService();
	    		systemLog.setServiceGuid(service.getGuid());
	    		
	    		EventObject systemLogEventObject = new SystemLogEventObj(this);
	    		Map systemLogMap = new HashMap();
	    		systemLogMap.put("systemLog", systemLog);
	    		systemLogMap.put("keyName", "tablefieldadd");
	    		systemLogMap.put("tableName", tableName);
	    		systemLogMap.put("field", field);
	    		
	    		systemLogEventObject.setDataMap(systemLogMap);
	    		ContextUtil.getAc().publishEvent(systemLogEventObject);
				
				ldb.set("success", true);
				ldb.set("reason", reason);
				this.json = JSONObject.fromObject(ldb).toString();
			}catch(Exception e){
				ldb.set("success", false);
				ldb.set("reason", reason);
				this.json = JSONObject.fromObject(ldb).toString();
			}			
		}else{
			ldb.set("success", false);
			ldb.set("reason", "数据库表不存在！");
			this.json = JSONObject.fromObject(ldb).toString();
		}

		return AJAX;
	}
		
	@Action(value="alterTableColumn")
	public String alterTableColumn() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("alterTableColumn() - start"); //$NON-NLS-1$
		}

		catalog = (Catalog)catalogManager.getObject(Catalog.class, node);
		String tableName = catalog.getTableName().trim();
		LazyDynaBean ldb = new  LazyDynaBean();
		String reason = "";
		
		if(dbMetaDataManager.checkTableExist(tableName)){
			try{
				List lstColumns = dbMetaDataManager.listAllColumns(tableName);
				
				String dbName = dbMetaDataManager.getDatabaseProductName();
				
				DbColumn[] dbcs = (DbColumn[])JSONUtil.stringToArray(json, DbColumn.class);	
				if(dbName.indexOf("MySQL") > -1){
					for (DbColumn dbc :dbcs){
						if(dbc.getColumn_name_old().trim().length() == 0){ //增加字段
							String DDL = "ALTER TABLE " + tableName + " ADD COLUMN " + dbc.getColumn_name() + " ";
							String sType = dbc.getType_name();
							if(
								sType.equalsIgnoreCase("CHAR") ||
							    sType.equalsIgnoreCase("VARCHAR")
							){
								DDL = DDL + sType + "(" + dbc.getData_length() + ")";
							}else if(
								sType.equalsIgnoreCase("DECIMAL") ||
							    sType.equalsIgnoreCase("NUMERIC")	
							){
								DDL = DDL + sType + "(" + dbc.getData_length() + ",3)";
							}else{
								DDL = DDL + sType;
							}
							
							if(dbc.getNullable() == true){
								DDL = DDL + " DEFAULT NULL";
							}else{
								DDL = DDL + " NOT NULL";
							}
							if(dbc.getComment().length() > 0){
								DDL = DDL + " COMMENT '" + dbc.getComment() + "'";
							}

							try{
								dbMetaDataManager.executeDDL(DDL);
								hibernateLoader.loadNewDbDefinition(tableName);
								reason = reason + "\r\n" + DDL + "\r\n  [成功！]";
							}catch(Exception e){
								logger.error("alterTableColumn()", e); //$NON-NLS-1$

								reason = reason + "\r\n" + DDL + "\r\n  [" + e.getMessage() + "]";
								e.printStackTrace();
							}	
						}else{ //修改字段
							String DDL = "ALTER TABLE " + tableName;
							DbColumn c = null;
							for(Object column : lstColumns){
								c = (DbColumn)column;
								if(c.getColumn_name().equalsIgnoreCase(dbc.getColumn_name_old())){									
									break;
								}
							}
							if(dbc.getColumn_name().equalsIgnoreCase(dbc.getColumn_name_old())){ //字段名称没有改变
								DDL = DDL + " MODIFY COLUMN " + dbc.getColumn_name() + " ";
							}else{
								DDL = DDL + " CHANGE COLUMN " + dbc.getColumn_name_old() + " " + dbc.getColumn_name() + " " ;
							}
							
							String sType = dbc.getType_name();
							if(
								sType.equalsIgnoreCase("CHAR") ||
							    sType.equalsIgnoreCase("VARCHAR")
							){
								DDL = DDL + sType + "(" + dbc.getData_length() + ")";
							}else if(
								sType.equalsIgnoreCase("DECIMAL") ||
							    sType.equalsIgnoreCase("NUMERIC")	
							){
								DDL = DDL + sType + "(" + dbc.getData_length() + ",3)";
							}else{
								DDL = DDL + sType;
							}

							if(dbc.getNullable() == true){
								DDL = DDL + " DEFAULT NULL";
							}else{
								DDL = DDL + " NOT NULL";
							}
							if(dbc.getComment().length() > 0){
								DDL = DDL + " COMMENT '" + dbc.getComment() + "'";
							}
							
							try{
								dbMetaDataManager.executeDDL(DDL);
								hibernateLoader.loadNewDbDefinition(tableName);
								reason = reason + "\r\n" + DDL + "\r\n  [success!]";
							}catch(Exception e){
								logger.error("alterTableColumn()", e); //$NON-NLS-1$

								reason = reason + "\r\n" + DDL + "\r\n  [" + e.getMessage() + "]";
							}							 
						}
					}	
				}else if("Oracle".equalsIgnoreCase(dbName)){
					for (DbColumn dbc :dbcs){
						if(dbc.getColumn_name_old().trim().length() == 0){ //增加字段
							String DDL = "ALTER TABLE " + tableName + " ADD " + dbc.getColumn_name() + " ";
							String sType = dbc.getType_name();
							if(
								sType.equalsIgnoreCase("CHAR") ||
								sType.equalsIgnoreCase("NCHAR") ||
							    sType.equalsIgnoreCase("VARCHAR2") ||
							    sType.equalsIgnoreCase("NVARCHAR2") ||
							    sType.equalsIgnoreCase("RAW")
							){
								DDL = DDL + sType + "(" + dbc.getData_length() + ")";
							}else if(
								sType.equalsIgnoreCase("DECIMAL") ||
							    sType.equalsIgnoreCase("NUMERIC")	
							){
								DDL = DDL + sType + "(" + dbc.getData_length() + ",3)";
							}else{
								DDL = DDL + sType;
							}
							
							if(dbc.getNullable() == true){
								//DDL = DDL + " DEFAULT NULL";
							}else{
								DDL = DDL + " NOT NULL";
							}							
							 
							try{
								dbMetaDataManager.executeDDL(DDL);
								if(dbc.getComment().length() > 0){
									dbMetaDataManager.executeDDL("COMMENT ON COLUMN " + tableName.trim().toUpperCase() + "." + dbc.getColumn_name().trim().toUpperCase() + " IS '" + dbc.getComment() + "'");
								}

								hibernateLoader.loadNewDbDefinition(tableName);
								
								reason = reason + "\r\n" + DDL + "\r\n  [success!]";
							}catch(Exception e){
								logger.error("alterTableColumn()", e); //$NON-NLS-1$

								reason = reason + "\r\n" + DDL + "\r\n  [" + e.getMessage() + "]";
								e.printStackTrace();
							}							 
						}else{ //修改字段
							try{
								if(dbc.getComment().length() > 0){
									dbMetaDataManager.executeDDL("COMMENT ON COLUMN " + tableName.trim().toUpperCase() + "." + dbc.getColumn_name().trim().toUpperCase() + " IS '" + dbc.getComment() + "'");
								}
							}catch(Exception e){
								logger.error("alterTableColumn()", e); //$NON-NLS-1$

								e.printStackTrace();
							}							 

							String DDL = "ALTER TABLE " + tableName;
							DbColumn c = null;
							for(Object column : lstColumns){
								c = (DbColumn)column;
								if(c.getColumn_name().equalsIgnoreCase(dbc.getColumn_name_old())){									
									break;
								}
							}
							if(dbc.getColumn_name().equalsIgnoreCase(dbc.getColumn_name_old())){ //字段名称没有改变
								DDL = DDL + " MODIFY " + dbc.getColumn_name() + " ";
							}else{
								try{
									dbMetaDataManager.executeDDL(DDL + " RENAME COLUMN " + dbc.getColumn_name_old() + " TO " + dbc.getColumn_name());
								}catch(Exception e){
									logger.error("alterTableColumn()", e); //$NON-NLS-1$

									reason = reason + "\r\n" + DDL + "\r\n  [" + e.getMessage() + "]";
									e.printStackTrace();
								}	
								DDL = DDL + " MODIFY " + dbc.getColumn_name() + " ";
							}
							
							String sType = dbc.getType_name();
							if(
								sType.equalsIgnoreCase("CHAR") ||
								sType.equalsIgnoreCase("NCHAR") ||
							    sType.equalsIgnoreCase("VARCHAR2") ||
							    sType.equalsIgnoreCase("NVARCHAR2") ||
							    sType.equalsIgnoreCase("RAW")
							){
								DDL = DDL + sType + "(" + dbc.getData_length() + ")";
							}else if(
								sType.equalsIgnoreCase("DECIMAL") ||
							    sType.equalsIgnoreCase("NUMERIC")	
							){
								DDL = DDL + sType + "(" + dbc.getData_length() + ",3)";
							}else{
								DDL = DDL + sType;
							}

							if(dbc.getNullable() == true){
								DDL = DDL + " NULL";
							}else{
								DDL = DDL + " NOT NULL";
							}
							
							try{
								dbMetaDataManager.executeDDL(DDL);
								hibernateLoader.loadNewDbDefinition(tableName);
								reason = reason + "\r\n" + DDL + "\r\n  [success!]";
							}catch(Exception e){
								logger.error("alterTableColumn()", e); //$NON-NLS-1$

								reason = reason + "\r\n" + DDL + "\r\n  [" + e.getMessage() + "]";
								e.printStackTrace();
							}							 
						}
					}						
				}

				User user = this.getSessionUser();
				
//	    		记录日志
	    		SystemLog systemLog = new SystemLog();
	    		systemLog.setOpterateType(SystemLog.OPTERATETYPE_ADD);
	    		systemLog.setUser(user);
	    		
	    		Service service = this.getDefaultService();
	    		systemLog.setServiceGuid(service.getGuid());
	    		
	    		EventObject systemLogEventObject = new SystemLogEventObj(this);
	    		Map systemLogMap = new HashMap();
	    		systemLogMap.put("systemLog", systemLog);
	    		systemLogMap.put("keyName", "tablefieldaddorupdate");
	    		systemLogMap.put("tableName", tableName);
	    		
	    		systemLogEventObject.setDataMap(systemLogMap);
	    		ContextUtil.getAc().publishEvent(systemLogEventObject);
				
				ldb.set("success", true);
				//ldb.set("reason", reason);
				ldb.set("reason", "修改成功");
				this.json = JSONObject.fromObject(ldb).toString();
			}catch(Exception e){
				logger.error("alterTableColumn()", e); //$NON-NLS-1$

				ldb.set("success", false);
//				ldb.set("reason", reason);
				ldb.set("reason", "修改时发生错误，错误的原因："+e.getMessage());
				this.json = JSONObject.fromObject(ldb).toString();
			}
		}
		

		if (logger.isDebugEnabled()) {
			logger.debug("alterTableColumn() - end"); //$NON-NLS-1$
		}
		return AJAX;
	}

	private int getCatalogType(String tableName){
		int catalogType = 0;
		
		if(tableName.trim().toLowerCase().startsWith("dyna_so_")){
			catalogType = 1;
		}else if(tableName.trim().toLowerCase().startsWith("dyna_data_")){
			catalogType = 2;
		}else if(tableName.trim().toLowerCase().startsWith("dyna_dataset_")){
			catalogType = 3;
		}else if(tableName.trim().toLowerCase().startsWith("dyna_catalog_")){
			catalogType = 4;
		}else if(tableName.trim().toLowerCase().startsWith("dyna_dict_")){
			catalogType = 5;
		}
		
		return catalogType;
	}
	
	private String getDefaultDDL4MySql(String tableName){
		String DDL = "";
		
		if(tableName.trim().toLowerCase().startsWith("dyna_so_")){
			DDL="CREATE TABLE " + tableName + " (" + 
				  "Catalog_GUID varchar(38) NOT NULL COMMENT 'Catalog标识符'," +
				  "Item_GUID varchar(38) NOT NULL COMMENT '唯一标识符'," +
				  "Item_Code varchar(50) NOT NULL COMMENT '代码'," +
				  "Item_Name varchar(100) NOT NULL COMMENT '名称'," +
				  "Item_ParentGUID varchar(38) DEFAULT NULL COMMENT '父节点的GUID',"+ 
				  "Flag varchar(100) default NULL COMMENT 'Flag状态标记',"+ 
				  "Status int DEFAULT 0 COMMENT 'Status状态标记',"+ 
				  "TabIndex double default NULL COMMENT '排列序号',"+ 
				  "PRIMARY KEY (Item_GUID)"+
				")";			
		}else if(tableName.trim().toLowerCase().startsWith("dyna_data_")){
			DDL="CREATE TABLE " + tableName + " (" + 
			  "ReportInstance_Guid varchar(38) NOT NULL COMMENT '报表实例'," +
			  "TabIndex double default NULL COMMENT '排列序号',"+ 
			  "PRIMARY KEY (ReportInstance_Guid)"+
			")";
		}else if(tableName.trim().toLowerCase().startsWith("dyna_dataset_")){
			DDL="CREATE TABLE " + tableName + " (" + 
			  "Item_GUID varchar(38) NOT NULL COMMENT '唯一标识符'," +
			  "ReportInstance_Guid varchar(38) NOT NULL COMMENT '报表实例'," +
			  "TabIndex double default NULL COMMENT '排列序号',"+ 
			  "PRIMARY KEY (Item_GUID)"+
			")";
		}else if(tableName.trim().toLowerCase().startsWith("dyna_catalog_")){
			DDL="CREATE TABLE " + tableName + " (" + 
			  "Item_GUID varchar(38) NOT NULL COMMENT '唯一标识符'," +
			  "Item_Code varchar(50) NOT NULL COMMENT '代码'," +
			  "Item_Name varchar(100) NOT NULL COMMENT '名称'," +
			  "Item_ParentGUID varchar(38) DEFAULT NULL COMMENT '父节点的GUID',"+ 
			  "TabIndex double default NULL COMMENT '排列序号',"+ 
			  "PRIMARY KEY (Item_GUID)"+
			")";
		}else if(tableName.trim().toLowerCase().startsWith("dyna_dict_")){
			DDL="CREATE TABLE " + tableName + " (" + 
			  "Item_GUID varchar(38) NOT NULL COMMENT '唯一标识符'," +
			  "Item_Code varchar(50) NOT NULL COMMENT '代码'," +
			  "Item_Name varchar(100) NOT NULL COMMENT '名称'," +
			  "Item_Type varchar(100) NOT NULL COMMENT '类型'," +
			  "TabIndex double default NULL COMMENT '排列序号',"+ 
			  "PRIMARY KEY (Item_GUID)"+
			")";
		}
		
		return DDL;
	}

	private String getDefaultDDL4Oracle(String tableName){
		String DDL = "";
		
		if(tableName.trim().toLowerCase().startsWith("dyna_so_")){
			DDL="CREATE TABLE " + tableName + " (" + 
				  "Catalog_GUID varchar2(38) NOT NULL COMMENT 'Catalog标识符'," +
				  "Item_GUID varchar2(38) NOT NULL COMMENT '唯一标识符'," +
				  "Item_Code varchar2(50) NOT NULL COMMENT '代码'," +
				  "Item_Name varchar2(100) NOT NULL COMMENT '名称'," +
				  "Item_ParentGUID varchar2(38) DEFAULT NULL COMMENT '父节点的GUID',"+ 
				  "Flag varchar2(100) DEFAULT NULL COMMENT 'Flag状态标记',"+
				  "Status number(10) DEFAULT 0 COMMENT 'Status状态标记',"+ 
				  "TabIndex number(20,3) NOT NULL COMMENT '排列序号',"+ 
				  "PRIMARY KEY (Item_GUID)"+
				")";			
		}else if(tableName.trim().toLowerCase().startsWith("dyna_data_")){
			DDL="CREATE TABLE " + tableName + " (" + 
			  "ReportInstance_Guid varchar2(38) NOT NULL COMMENT '报表实例'," +
			  "TabIndex number(20,3) NOT NULL COMMENT '排列序号',"+ 
			  "PRIMARY KEY (ReportInstance_Guid)"+
			")";
		}else if(tableName.trim().toLowerCase().startsWith("dyna_dataset_")){
			DDL="CREATE TABLE " + tableName + " (" + 
			  "Item_GUID varchar2(38) NOT NULL COMMENT '唯一标识符'," +
			  "ReportInstance_Guid varchar2(38) NOT NULL COMMENT '报表实例'," +
			  "TabIndex number(20,3) NOT NULL COMMENT '排列序号',"+ 
			  "PRIMARY KEY (Item_GUID)"+
			")";
		}else if(tableName.trim().toLowerCase().startsWith("dyna_catalog_")){
			DDL="CREATE TABLE " + tableName + " (" + 
			  "Item_GUID varchar2(38) NOT NULL COMMENT '唯一标识符'," +
			  "Item_Code varchar2(50) NOT NULL COMMENT '代码'," +
			  "Item_Name varchar2(100) NOT NULL COMMENT '名称'," +
			  "Item_ParentGUID varchar2(38) DEFAULT NULL COMMENT '父节点的GUID',"+ 
			  "TabIndex number(20,3) NOT NULL COMMENT '排列序号',"+ 
			  "PRIMARY KEY (Item_GUID)"+
			")";
		}else if(tableName.trim().toLowerCase().startsWith("dyna_dict_")){
			DDL="CREATE TABLE " + tableName + " (" + 
			  "Item_GUID varchar2(38) NOT NULL COMMENT '唯一标识符'," +
			  "Item_Code varchar2(50) NOT NULL COMMENT '代码'," +
			  "Item_Name varchar2(100) NOT NULL COMMENT '名称'," +
			  "Item_Type varchar2(100) NOT NULL COMMENT '类型'," +
			  "TabIndex number(20,3) NOT NULL COMMENT '排列序号',"+ 
			  "PRIMARY KEY (Item_GUID)"+
			")";
		}
		
		return DDL;
	}

	private void DDL_CreateTable(String tableName) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("DDL_CreateTable(String) - start"); //$NON-NLS-1$
		}

		int catalogType =  getCatalogType(tableName);
		if(!dbMetaDataManager.checkTableExist(tableName)){
			try{
				String dbName = dbMetaDataManager.getDatabaseProductName();
				String dbVersion = dbMetaDataManager.getDatabaseProductVersion();
				int dbMajorVersion = dbMetaDataManager.getDatabaseMajorVersion();
				int dbMinorVersion = dbMetaDataManager.getDatabaseMinorVersion();
				
				if(dbName.indexOf("MySQL") > -1){					
					dbMetaDataManager.executeDDL(getDefaultDDL4MySql(tableName));
					hibernateLoader.loadNewDbDefinition(tableName);
				}else if(dbName.equalsIgnoreCase("Oracle")){
					dbMetaDataManager.executeDDL(getDefaultDDL4Oracle(tableName));

					hibernateLoader.loadNewDbDefinition(tableName);
				}
			}catch(Exception e){
				logger.error("DDL_CreateTable(String)", e); //$NON-NLS-1$

				e.printStackTrace();
			}
		}		

		if (logger.isDebugEnabled()) {
			logger.debug("DDL_CreateTable(String) - end"); //$NON-NLS-1$
		}
	}

	public String getField() {
		return field;
	}
	public void setField(String field) {
		this.field = field;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getCrud() {
		return crud;
	}
	public void setCrud(String crud) {
		this.crud = crud;
	}
	public static long getSerialVersionUID() {
		return serialVersionUID;
	}
	public Catalog getCatalog() {
		return catalog;
	}
	public void setCatalog(Catalog catalog) {
		this.catalog = catalog;
	}
	public CatalogManager getCatalogManager() {
		return catalogManager;
	}
	public void setCatalogManager(CatalogManager catalogManager) {
		this.catalogManager = catalogManager;
	}
	public HibernateLoader getHibernateLoader() {
		return hibernateLoader;
	}
	public void setHibernateLoader(HibernateLoader hibernateLoader) {
		this.hibernateLoader = hibernateLoader;
	}	
	public DbMetaDataManager getDbMetaDataManager() {
		return dbMetaDataManager;
	}
	public void setDbMetaDataManager(DbMetaDataManager dbMetaDataManager) {
		this.dbMetaDataManager = dbMetaDataManager;
	}		
	public DynaBeanManager getDynaBeanManager() {
		return dynaBeanManager;
	}
	public void setDynaBeanManager(DynaBeanManager dynaBeanManager) {
		this.dynaBeanManager = dynaBeanManager;
	}
	public HashMap<String,Object> getDynaBean() {
		return dynaBean;
	}
	public void setDynaBean(HashMap<String,Object> dynaBean) {
		this.dynaBean = dynaBean;
	}
	public String getJsonList() {
		return jsonList;
	}

	public void setJsonList(String jsonList) {
		this.jsonList = jsonList;
	}

	public String getJsonAdd() {
		return jsonAdd;
	}

	public void setJsonAdd(String jsonAdd) {
		this.jsonAdd = jsonAdd;
	}

	public String getJsonEdit() {
		return jsonEdit;
	}

	public void setJsonEdit(String jsonEdit) {
		this.jsonEdit = jsonEdit;
	}

	public String getDirtyFile() {
		return dirtyFile;
	}

	public void setDirtyFile(String dirtyFile) {
		this.dirtyFile = dirtyFile;
	}

	public SoTypeManager getSoTypeManager() {
		return soTypeManager;
	}

	public void setSoTypeManager(SoTypeManager soTypeManager) {
		this.soTypeManager = soTypeManager;
	}

	public static Logger getLogger() {
		return logger;
	}

	public ApplicationManager getApplicationManager() {
		return applicationManager;
	}

	public void setApplicationManager(ApplicationManager applicationManager) {
		this.applicationManager = applicationManager;
	}

	public String getApplicationGuid() {
		return applicationGuid;
	}

	public void setApplicationGuid(String applicationGuid) {
		this.applicationGuid = applicationGuid;
	}

	public String getApplicationName() {
		return applicationName;
	}

	public void setApplicationName(String applicationName) {
		this.applicationName = applicationName;
	}

	public String getServiceGuid() {
		return serviceGuid;
	}

	public void setServiceGuid(String serviceGuid) {
		this.serviceGuid = serviceGuid;
	}

	public StatisticalObjectTreeNodeManager getStatisticalObjectTreeNodeManager() {
		return statisticalObjectTreeNodeManager;
	}

	public void setStatisticalObjectTreeNodeManager(
			StatisticalObjectTreeNodeManager statisticalObjectTreeNodeManager) {
		this.statisticalObjectTreeNodeManager = statisticalObjectTreeNodeManager;
	}

	public TemplateManager getTemplateManager() {
		return templateManager;
	}

	public void setTemplateManager(TemplateManager templateManager) {
		this.templateManager = templateManager;
	}

}
